<template>
  <wu-card
    :leftIcon="leftIcon"
    :title="title"
    :rightIcon="rightIcon"
    :headBorderBottom="headBorderBottom"
  >
    <div class="wu-list-card">
      <div class="wu-navs d-flex jc-between py-3 fs-md text-dark-1">
        <template v-for="(category, index) in categories">
          <div
            @click="$refs.list.$swiper.slideTo(index)"
            class="wu-navs-item"
            :key="index"
            :class="{'active': index === activeIndex}"
          >{{category.name}}</div>
        </template>
      </div>
      <swiper
        ref="list"
        :options="swiperOptions"
        @slide-change="()=> activeIndex = $refs.list.$swiper.realIndex"
      >
        <swiper-slide v-for="(category, i) in categories" :key="i">
          <slot name="items" :category="category"></slot>
        </swiper-slide>
      </swiper>
    </div>
  </wu-card>
</template>

<script>
import wuCard from "@/components/wu-card";
export default {
  props: {
    categories: {
      type: Array,
      default: () => []
    },
    headBorderBottom: {
      type: Boolean,
      default: true
    },
    leftIcon: {
      type: String,
      required: true
    },
    title: {
      type: String,
      required: true
    },
    rightIcon: {
      type: String,
      default: "icon-menu"
    }
  },
  components: {
    wuCard
  },
  data() {
    return {
      activeIndex: 0,
      swiperOptions: {
        autoHeight: true
      }
    };
  }
};
</script>

<style scoped lang="scss">
@import "~@/assets/scss/variables.scss";
.wu-navs {
  &-item {
    padding-bottom: 3px;
    border-bottom: 3px solid transparent;
  }
  &-item.active {
    color: map-get($colors, "primary");
    border-color: map-get($colors, "primary");
  }
}
</style>